{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## 实验整体架构\n",
    "```mermaid\n",
    "graph TD\n",
    "    A[数据准备] --> B[GDP数据处理]\n",
    "    A --> C[行政区划Shp数据]\n",
    "    B --> D[时间序列预测]\n",
    "    C --> E[空间数据分析]\n",
    "    D --> F[GDP预测结果]\n",
    "    E --> G[空间自相关分析]\n",
    "    E --> H[冷热点分析]\n",
    "    F --> I[可视化系统]\n",
    "    G --> I\n",
    "    H --> I\n",
    "```"
   ],
   "id": "9ec42de3902a1c40"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 1.导包",
   "id": "3a19e2cd325f42d"
  },
  {
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-08-26T10:46:53.552859Z",
     "start_time": "2025-08-26T10:46:52.579957Z"
    }
   },
   "cell_type": "code",
   "outputs": [],
   "execution_count": 11,
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import geopandas as gpd\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.preprocessing import MinMaxScaler"
   ],
   "id": "initial_id"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 2.数据加载与预处理",
   "id": "9e04e9f2a36ce81c"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-26T10:26:19.791724Z",
     "start_time": "2025-08-26T10:26:19.760184Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import chardet\n",
    "\n",
    "# 检测文件编码\n",
    "with open('data/original_data/分省年度数据.csv', 'rb') as f:\n",
    "    result = chardet.detect(f.read())\n",
    "    print(f\"检测到的编码: {result['encoding']}\")"
   ],
   "id": "627d7f58d1a81721",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "检测到的编码: GB2312\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-26T10:27:08.606079Z",
     "start_time": "2025-08-26T10:27:08.598170Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 读取文件并重新保存为UTF-8编码\n",
    "with open('data/original_data/分省年度数据.csv', 'r', encoding='GB2312') as f:\n",
    "    content = f.read()\n",
    "\n",
    "with open('data/original_data/分省年度数据_utf8.csv', 'w', encoding='utf-8') as f:\n",
    "    f.write(content)"
   ],
   "id": "6d38462bd252db67",
   "outputs": [],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-26T10:50:20.124905Z",
     "start_time": "2025-08-26T10:50:20.115965Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 读取文件，跳过前3行注释\n",
    "df = pd.read_csv('data/original_data/分省年度数据_utf8.csv',\n",
    "                 skiprows=3,\n",
    "                 skipfooter=2,  # 跳过最后2行\n",
    "                 encoding='utf-8',\n",
    "                 engine='python')  # 必须指定engine为python才能使用skipfooter)\n",
    "\n",
    "# 设置地区为索引\n",
    "df.set_index('地区', inplace=True)\n",
    "df = df.astype(float)\n",
    "\n",
    "# 转置为实践序列格式\n",
    "df_time = df.T\n",
    "# 原始代码中str.replace('年', '-')将\"2024年\"变成了\"2024-\"，而格式%Y只接受纯年份数字\n",
    "df_time.index = pd.to_datetime(df_time.index.str.replace('年', ''), format='%Y')"
   ],
   "id": "a8a3678d57a6ecc7",
   "outputs": [],
   "execution_count": 15
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-26T10:50:21.549828Z",
     "start_time": "2025-08-26T10:50:21.526460Z"
    }
   },
   "cell_type": "code",
   "source": "df",
   "id": "830c3f87685c26fd",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "             2024年     2023年     2022年     2021年     2020年     2019年  \\\n",
       "地区                                                                     \n",
       "北京市        49843.1   47353.7   45222.4   44350.7   38503.6   37767.0   \n",
       "天津市        18024.3   17211.8   16588.5   16093.2   14230.8   14097.2   \n",
       "河北省        47526.9   45660.0   43198.3   41205.4   36821.5   35623.5   \n",
       "山西省        25494.7   26050.8   25653.2   23087.8   18202.7   17311.0   \n",
       "内蒙古自治区     26314.6   25020.5   23795.7   21584.8   17623.4   17479.4   \n",
       "辽宁省        32612.7   31389.8   29739.7   28471.0   25839.0   25665.9   \n",
       "吉林省        14361.2   13942.7   13121.4   13431.1   12499.5   11949.4   \n",
       "黑龙江省       16476.9   16470.7   16359.2   15292.8   14000.1   13962.5   \n",
       "上海市        53926.7   51404.5   48594.5   47059.4   41603.9   40241.2   \n",
       "江苏省       137008.0  130924.3  124564.2  119853.2  104566.6   99836.9   \n",
       "浙江省        90130.6   85619.6   80770.0   76765.3   67164.5   64632.0   \n",
       "安徽省        50625.2   48227.5   45525.1   43102.8   38628.8   37584.8   \n",
       "福建省        57761.0   54801.7   52099.6   49602.6   43682.0   42479.1   \n",
       "江西省        34202.5   32677.1   31568.1   29838.2   25825.4   24724.0   \n",
       "山东省        98565.8   94206.4   89519.4   84838.0   74355.9   72024.3   \n",
       "河南省        63590.0   60627.7   58807.4   57806.9   54160.6   53739.3   \n",
       "湖北省        60013.0   56794.3   53445.4   50093.3   43017.6   45557.0   \n",
       "湖南省        53231.0   50667.5   47957.9   45751.9   41693.7   39930.7   \n",
       "广东省       141633.8  137905.4  132547.1  127577.4  113708.9  110468.1   \n",
       "广西壮族自治区    28649.4   27501.7   26419.7   25311.5   22250.7   21341.5   \n",
       "海南省         7935.7    7590.2    6912.8    6508.9    5640.8    5442.1   \n",
       "重庆市        32193.2   30614.3   28771.8   28092.5   25158.1   23689.6   \n",
       "四川省        64697.0   61353.4   57609.4   55131.3   49445.1   47168.6   \n",
       "贵州省        22667.1   21513.7   20579.5   19921.3   18308.3   17251.8   \n",
       "云南省        31534.1   30595.8   29301.1   27895.3   25214.5   23902.1   \n",
       "西藏自治区       2764.9    2532.9    2235.4    2145.1    1956.5    1750.3   \n",
       "陕西省        35538.8   33976.5   33035.6   30476.6   26297.0   26214.5   \n",
       "甘肃省        13002.9   12345.7   11553.6   10608.0    9323.1    9053.3   \n",
       "青海省         3950.8    3849.2    3677.4    3446.3    3080.6    3020.2   \n",
       "宁夏回族自治区     5502.8    5368.8    5168.1    4666.5    4036.2    3841.5   \n",
       "新疆维吾尔自治区   20534.1   19603.3   18550.5   16791.5   14262.2   14024.9   \n",
       "\n",
       "             2018年    2017年    2016年    2015年  \n",
       "地区                                             \n",
       "北京市        35161.4  31325.9  28438.7  26034.1  \n",
       "天津市        13411.1  12468.2  11487.0  10889.2  \n",
       "河北省        32947.0  31065.5  28879.7  26744.1  \n",
       "山西省        16153.1  14679.1  12160.1  12036.1  \n",
       "内蒙古自治区     16252.9  15009.9  13879.0  13062.7  \n",
       "辽宁省        24113.5  22105.4  20832.0  20657.8  \n",
       "吉林省        11437.4  11083.0  10603.5  10162.9  \n",
       "黑龙江省       13205.7  12659.5  12280.9  12023.2  \n",
       "上海市        37769.1  34378.3  30963.9  27821.6  \n",
       "江苏省        93456.3  86512.9  78261.2  71876.0  \n",
       "浙江省        59311.7  53135.2  48095.8  44222.0  \n",
       "安徽省        34377.3  30141.8  26801.2  24142.7  \n",
       "福建省        39204.8  34432.2  30199.2  27307.5  \n",
       "江西省        23016.9  20497.6  18761.2  17031.1  \n",
       "山东省        67864.4  63958.6  59702.6  56159.1  \n",
       "河南省        50273.5  44586.5  40167.7  36798.2  \n",
       "湖北省        42425.5  37624.2  33767.6  30661.6  \n",
       "湖南省        36629.3  34127.7  31225.0  28811.7  \n",
       "广东省       101875.9  93004.8  83493.4  75820.8  \n",
       "广西壮族自治区    19951.7  18071.7  16417.2  15030.2  \n",
       "海南省         5004.2   4552.9   4151.0   3782.7  \n",
       "重庆市        21866.8  20260.8  18271.1  16305.9  \n",
       "四川省        43539.0  38517.1  33879.2  30829.1  \n",
       "贵州省        15886.6  14067.3  12133.9  10887.1  \n",
       "云南省        21427.5  18864.6  16773.6  15358.6  \n",
       "西藏自治区       1583.5   1381.0   1197.4   1063.6  \n",
       "陕西省        24354.8  21776.1  19354.6  18188.3  \n",
       "甘肃省         8364.7   7642.6   7207.1   6793.4  \n",
       "青海省         2799.9   2517.0   2310.7   2054.3  \n",
       "宁夏回族自治区     3580.6   3271.6   2853.3   2644.7  \n",
       "新疆维吾尔自治区   13110.1  11460.8   9913.9   9545.7  "
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2024年</th>\n",
       "      <th>2023年</th>\n",
       "      <th>2022年</th>\n",
       "      <th>2021年</th>\n",
       "      <th>2020年</th>\n",
       "      <th>2019年</th>\n",
       "      <th>2018年</th>\n",
       "      <th>2017年</th>\n",
       "      <th>2016年</th>\n",
       "      <th>2015年</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>地区</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>北京市</th>\n",
       "      <td>49843.1</td>\n",
       "      <td>47353.7</td>\n",
       "      <td>45222.4</td>\n",
       "      <td>44350.7</td>\n",
       "      <td>38503.6</td>\n",
       "      <td>37767.0</td>\n",
       "      <td>35161.4</td>\n",
       "      <td>31325.9</td>\n",
       "      <td>28438.7</td>\n",
       "      <td>26034.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>天津市</th>\n",
       "      <td>18024.3</td>\n",
       "      <td>17211.8</td>\n",
       "      <td>16588.5</td>\n",
       "      <td>16093.2</td>\n",
       "      <td>14230.8</td>\n",
       "      <td>14097.2</td>\n",
       "      <td>13411.1</td>\n",
       "      <td>12468.2</td>\n",
       "      <td>11487.0</td>\n",
       "      <td>10889.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>河北省</th>\n",
       "      <td>47526.9</td>\n",
       "      <td>45660.0</td>\n",
       "      <td>43198.3</td>\n",
       "      <td>41205.4</td>\n",
       "      <td>36821.5</td>\n",
       "      <td>35623.5</td>\n",
       "      <td>32947.0</td>\n",
       "      <td>31065.5</td>\n",
       "      <td>28879.7</td>\n",
       "      <td>26744.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>山西省</th>\n",
       "      <td>25494.7</td>\n",
       "      <td>26050.8</td>\n",
       "      <td>25653.2</td>\n",
       "      <td>23087.8</td>\n",
       "      <td>18202.7</td>\n",
       "      <td>17311.0</td>\n",
       "      <td>16153.1</td>\n",
       "      <td>14679.1</td>\n",
       "      <td>12160.1</td>\n",
       "      <td>12036.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>内蒙古自治区</th>\n",
       "      <td>26314.6</td>\n",
       "      <td>25020.5</td>\n",
       "      <td>23795.7</td>\n",
       "      <td>21584.8</td>\n",
       "      <td>17623.4</td>\n",
       "      <td>17479.4</td>\n",
       "      <td>16252.9</td>\n",
       "      <td>15009.9</td>\n",
       "      <td>13879.0</td>\n",
       "      <td>13062.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>辽宁省</th>\n",
       "      <td>32612.7</td>\n",
       "      <td>31389.8</td>\n",
       "      <td>29739.7</td>\n",
       "      <td>28471.0</td>\n",
       "      <td>25839.0</td>\n",
       "      <td>25665.9</td>\n",
       "      <td>24113.5</td>\n",
       "      <td>22105.4</td>\n",
       "      <td>20832.0</td>\n",
       "      <td>20657.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>吉林省</th>\n",
       "      <td>14361.2</td>\n",
       "      <td>13942.7</td>\n",
       "      <td>13121.4</td>\n",
       "      <td>13431.1</td>\n",
       "      <td>12499.5</td>\n",
       "      <td>11949.4</td>\n",
       "      <td>11437.4</td>\n",
       "      <td>11083.0</td>\n",
       "      <td>10603.5</td>\n",
       "      <td>10162.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黑龙江省</th>\n",
       "      <td>16476.9</td>\n",
       "      <td>16470.7</td>\n",
       "      <td>16359.2</td>\n",
       "      <td>15292.8</td>\n",
       "      <td>14000.1</td>\n",
       "      <td>13962.5</td>\n",
       "      <td>13205.7</td>\n",
       "      <td>12659.5</td>\n",
       "      <td>12280.9</td>\n",
       "      <td>12023.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>上海市</th>\n",
       "      <td>53926.7</td>\n",
       "      <td>51404.5</td>\n",
       "      <td>48594.5</td>\n",
       "      <td>47059.4</td>\n",
       "      <td>41603.9</td>\n",
       "      <td>40241.2</td>\n",
       "      <td>37769.1</td>\n",
       "      <td>34378.3</td>\n",
       "      <td>30963.9</td>\n",
       "      <td>27821.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>江苏省</th>\n",
       "      <td>137008.0</td>\n",
       "      <td>130924.3</td>\n",
       "      <td>124564.2</td>\n",
       "      <td>119853.2</td>\n",
       "      <td>104566.6</td>\n",
       "      <td>99836.9</td>\n",
       "      <td>93456.3</td>\n",
       "      <td>86512.9</td>\n",
       "      <td>78261.2</td>\n",
       "      <td>71876.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>浙江省</th>\n",
       "      <td>90130.6</td>\n",
       "      <td>85619.6</td>\n",
       "      <td>80770.0</td>\n",
       "      <td>76765.3</td>\n",
       "      <td>67164.5</td>\n",
       "      <td>64632.0</td>\n",
       "      <td>59311.7</td>\n",
       "      <td>53135.2</td>\n",
       "      <td>48095.8</td>\n",
       "      <td>44222.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>安徽省</th>\n",
       "      <td>50625.2</td>\n",
       "      <td>48227.5</td>\n",
       "      <td>45525.1</td>\n",
       "      <td>43102.8</td>\n",
       "      <td>38628.8</td>\n",
       "      <td>37584.8</td>\n",
       "      <td>34377.3</td>\n",
       "      <td>30141.8</td>\n",
       "      <td>26801.2</td>\n",
       "      <td>24142.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>福建省</th>\n",
       "      <td>57761.0</td>\n",
       "      <td>54801.7</td>\n",
       "      <td>52099.6</td>\n",
       "      <td>49602.6</td>\n",
       "      <td>43682.0</td>\n",
       "      <td>42479.1</td>\n",
       "      <td>39204.8</td>\n",
       "      <td>34432.2</td>\n",
       "      <td>30199.2</td>\n",
       "      <td>27307.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>江西省</th>\n",
       "      <td>34202.5</td>\n",
       "      <td>32677.1</td>\n",
       "      <td>31568.1</td>\n",
       "      <td>29838.2</td>\n",
       "      <td>25825.4</td>\n",
       "      <td>24724.0</td>\n",
       "      <td>23016.9</td>\n",
       "      <td>20497.6</td>\n",
       "      <td>18761.2</td>\n",
       "      <td>17031.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>山东省</th>\n",
       "      <td>98565.8</td>\n",
       "      <td>94206.4</td>\n",
       "      <td>89519.4</td>\n",
       "      <td>84838.0</td>\n",
       "      <td>74355.9</td>\n",
       "      <td>72024.3</td>\n",
       "      <td>67864.4</td>\n",
       "      <td>63958.6</td>\n",
       "      <td>59702.6</td>\n",
       "      <td>56159.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>河南省</th>\n",
       "      <td>63590.0</td>\n",
       "      <td>60627.7</td>\n",
       "      <td>58807.4</td>\n",
       "      <td>57806.9</td>\n",
       "      <td>54160.6</td>\n",
       "      <td>53739.3</td>\n",
       "      <td>50273.5</td>\n",
       "      <td>44586.5</td>\n",
       "      <td>40167.7</td>\n",
       "      <td>36798.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖北省</th>\n",
       "      <td>60013.0</td>\n",
       "      <td>56794.3</td>\n",
       "      <td>53445.4</td>\n",
       "      <td>50093.3</td>\n",
       "      <td>43017.6</td>\n",
       "      <td>45557.0</td>\n",
       "      <td>42425.5</td>\n",
       "      <td>37624.2</td>\n",
       "      <td>33767.6</td>\n",
       "      <td>30661.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖南省</th>\n",
       "      <td>53231.0</td>\n",
       "      <td>50667.5</td>\n",
       "      <td>47957.9</td>\n",
       "      <td>45751.9</td>\n",
       "      <td>41693.7</td>\n",
       "      <td>39930.7</td>\n",
       "      <td>36629.3</td>\n",
       "      <td>34127.7</td>\n",
       "      <td>31225.0</td>\n",
       "      <td>28811.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>广东省</th>\n",
       "      <td>141633.8</td>\n",
       "      <td>137905.4</td>\n",
       "      <td>132547.1</td>\n",
       "      <td>127577.4</td>\n",
       "      <td>113708.9</td>\n",
       "      <td>110468.1</td>\n",
       "      <td>101875.9</td>\n",
       "      <td>93004.8</td>\n",
       "      <td>83493.4</td>\n",
       "      <td>75820.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>广西壮族自治区</th>\n",
       "      <td>28649.4</td>\n",
       "      <td>27501.7</td>\n",
       "      <td>26419.7</td>\n",
       "      <td>25311.5</td>\n",
       "      <td>22250.7</td>\n",
       "      <td>21341.5</td>\n",
       "      <td>19951.7</td>\n",
       "      <td>18071.7</td>\n",
       "      <td>16417.2</td>\n",
       "      <td>15030.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>海南省</th>\n",
       "      <td>7935.7</td>\n",
       "      <td>7590.2</td>\n",
       "      <td>6912.8</td>\n",
       "      <td>6508.9</td>\n",
       "      <td>5640.8</td>\n",
       "      <td>5442.1</td>\n",
       "      <td>5004.2</td>\n",
       "      <td>4552.9</td>\n",
       "      <td>4151.0</td>\n",
       "      <td>3782.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>重庆市</th>\n",
       "      <td>32193.2</td>\n",
       "      <td>30614.3</td>\n",
       "      <td>28771.8</td>\n",
       "      <td>28092.5</td>\n",
       "      <td>25158.1</td>\n",
       "      <td>23689.6</td>\n",
       "      <td>21866.8</td>\n",
       "      <td>20260.8</td>\n",
       "      <td>18271.1</td>\n",
       "      <td>16305.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>四川省</th>\n",
       "      <td>64697.0</td>\n",
       "      <td>61353.4</td>\n",
       "      <td>57609.4</td>\n",
       "      <td>55131.3</td>\n",
       "      <td>49445.1</td>\n",
       "      <td>47168.6</td>\n",
       "      <td>43539.0</td>\n",
       "      <td>38517.1</td>\n",
       "      <td>33879.2</td>\n",
       "      <td>30829.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>贵州省</th>\n",
       "      <td>22667.1</td>\n",
       "      <td>21513.7</td>\n",
       "      <td>20579.5</td>\n",
       "      <td>19921.3</td>\n",
       "      <td>18308.3</td>\n",
       "      <td>17251.8</td>\n",
       "      <td>15886.6</td>\n",
       "      <td>14067.3</td>\n",
       "      <td>12133.9</td>\n",
       "      <td>10887.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>云南省</th>\n",
       "      <td>31534.1</td>\n",
       "      <td>30595.8</td>\n",
       "      <td>29301.1</td>\n",
       "      <td>27895.3</td>\n",
       "      <td>25214.5</td>\n",
       "      <td>23902.1</td>\n",
       "      <td>21427.5</td>\n",
       "      <td>18864.6</td>\n",
       "      <td>16773.6</td>\n",
       "      <td>15358.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>西藏自治区</th>\n",
       "      <td>2764.9</td>\n",
       "      <td>2532.9</td>\n",
       "      <td>2235.4</td>\n",
       "      <td>2145.1</td>\n",
       "      <td>1956.5</td>\n",
       "      <td>1750.3</td>\n",
       "      <td>1583.5</td>\n",
       "      <td>1381.0</td>\n",
       "      <td>1197.4</td>\n",
       "      <td>1063.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>陕西省</th>\n",
       "      <td>35538.8</td>\n",
       "      <td>33976.5</td>\n",
       "      <td>33035.6</td>\n",
       "      <td>30476.6</td>\n",
       "      <td>26297.0</td>\n",
       "      <td>26214.5</td>\n",
       "      <td>24354.8</td>\n",
       "      <td>21776.1</td>\n",
       "      <td>19354.6</td>\n",
       "      <td>18188.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>甘肃省</th>\n",
       "      <td>13002.9</td>\n",
       "      <td>12345.7</td>\n",
       "      <td>11553.6</td>\n",
       "      <td>10608.0</td>\n",
       "      <td>9323.1</td>\n",
       "      <td>9053.3</td>\n",
       "      <td>8364.7</td>\n",
       "      <td>7642.6</td>\n",
       "      <td>7207.1</td>\n",
       "      <td>6793.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>青海省</th>\n",
       "      <td>3950.8</td>\n",
       "      <td>3849.2</td>\n",
       "      <td>3677.4</td>\n",
       "      <td>3446.3</td>\n",
       "      <td>3080.6</td>\n",
       "      <td>3020.2</td>\n",
       "      <td>2799.9</td>\n",
       "      <td>2517.0</td>\n",
       "      <td>2310.7</td>\n",
       "      <td>2054.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>宁夏回族自治区</th>\n",
       "      <td>5502.8</td>\n",
       "      <td>5368.8</td>\n",
       "      <td>5168.1</td>\n",
       "      <td>4666.5</td>\n",
       "      <td>4036.2</td>\n",
       "      <td>3841.5</td>\n",
       "      <td>3580.6</td>\n",
       "      <td>3271.6</td>\n",
       "      <td>2853.3</td>\n",
       "      <td>2644.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新疆维吾尔自治区</th>\n",
       "      <td>20534.1</td>\n",
       "      <td>19603.3</td>\n",
       "      <td>18550.5</td>\n",
       "      <td>16791.5</td>\n",
       "      <td>14262.2</td>\n",
       "      <td>14024.9</td>\n",
       "      <td>13110.1</td>\n",
       "      <td>11460.8</td>\n",
       "      <td>9913.9</td>\n",
       "      <td>9545.7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 16
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 3.GDP时间序列预测",
   "id": "beb031844a080314"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "### 3.1 使用ARIMA进行预测（以北京市为例）\n",
    "**ARIMA** 是一种经典的时间序列预测方法，它的全称是 **AutoRegressive Integrated Moving Average**（自回归综合移动平均模型）。\n",
    "\n",
    "ARIMA是时间序列预测的基础方法，掌握它对于理解更复杂的模型（如Prophet、LSTM等）非常有帮助！\n",
    "\n",
    "#### ARIMA 的核心组成\n",
    "\n",
    "##### 1. AR (AutoRegressive) - 自回归部分\n",
    "\n",
    "- **含义**：用历史值预测当前值\n",
    "- **公式**：$y_t = c + \\phi_1 y_{t-1} + \\phi_2 y_{t-2} + \\dots + \\phi_p y_{t-p} + \\epsilon_t$\n",
    "- **参数 p**：表示使用前 p 个时间点的数据\n",
    "\n",
    "##### 2. I (Integrated) - 差分部分\n",
    "\n",
    "- **含义**：通过差分使非平稳时间序列变得平稳\n",
    "- **作用**：消除趋势和季节性\n",
    "- **参数 d**：表示差分的次数\n",
    "\n",
    "##### 3. MA (Moving Average) - 移动平均部分\n",
    "\n",
    "- **含义**：用历史预测误差来改进预测\n",
    "- **公式**：$y_t = \\mu + \\epsilon_t + \\theta_1 \\epsilon_{t-1} + \\theta_2 \\epsilon_{t-2} + \\dots + \\theta_q \\epsilon_{t-q}$\n",
    "- **参数 q**：表示使用前 q 个误差项\n",
    "\n",
    "#### ARIMA 模型的表示\n",
    "\n",
    "一个完整的ARIMA模型表示为：**ARIMA(p, d, q)**\n",
    "\n",
    "#### 如何选择参数 (p, d, q)\n",
    "\n",
    "##### 1. 确定 d（差分次数）：\n",
    "\n",
    "- **ADF检验**：p-value > 0.05 时需要差分\n",
    "- **观察趋势**：数据有明显趋势时需要差分\n",
    "\n",
    "##### 2. 确定 p（自回归阶数）：\n",
    "\n",
    "- 看**PACF图**：在哪个滞后后截尾\n",
    "- 比如PACF在滞后2后截尾，则 p=2\n",
    "\n",
    "##### 3. 确定 q（移动平均阶数）：\n",
    "\n",
    "- 看**ACF图**：在哪个滞后后截尾\n",
    "- 比如ACF在滞后1后截尾，则 q=1"
   ],
   "id": "5f33ff6eb72b3683"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-26T11:04:53.339210Z",
     "start_time": "2025-08-26T11:04:52.403687Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from statsmodels.tsa.arima.model import ARIMA\n",
    "from sklearn.metrics import mean_absolute_error, r2_score\n",
    "\n",
    "def arima_forecast(province_data, steps=3):\n",
    "    \"\"\"ARIMA预测\"\"\"\n",
    "    # 差分平稳化\n",
    "    diff_data = province_data.diff().dropna()\n",
    "\n",
    "    # 寻找最佳参数 (p,d,q)\n",
    "    best_aic = np.inf\n",
    "    best_order = None\n",
    "    best_model = None\n",
    "\n",
    "    # 参数搜索范围\n",
    "    for p in range(3):\n",
    "        for d in range(2):\n",
    "            for q in range(3):\n",
    "                try:\n",
    "                    model = ARIMA(province_data, order=(p, d, q))\n",
    "                    result = model.fit()\n",
    "                    if result.aic < best_aic:\n",
    "                        best_aic = result.aic\n",
    "                        best_order = (p, d, q)\n",
    "                        best_model = result\n",
    "                except:\n",
    "                    continue\n",
    "\n",
    "    print(f\"最佳ARIMA参数: {best_order}, AIC: {best_aic}\")\n",
    "\n",
    "    # 预测未来值\n",
    "    forecast = best_model.get_forecast(steps=steps)\n",
    "    forecast_values = forecast.predicted_mean\n",
    "    confidence_intervals = forecast.conf_int()\n",
    "\n",
    "    return forecast_values, confidence_intervals, best_model\n",
    "\n",
    "# 以北京市为例\n",
    "beijing_data = df_time['北京市']\n",
    "forecast_values, conf_int, model = arima_forecast(beijing_data, steps=3)\n",
    "\n",
    "print(f\"北京市未来3年GDP预测:\")\n",
    "for i, year in enumerate([2025, 2026, 2027]):\n",
    "    print(f\"{year}年: {forecast_values.iloc[i]:.1f}亿元\")"
   ],
   "id": "7545f31ef7997354",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-invertible starting MA parameters found.'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-invertible starting MA parameters found.'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-stationary starting autoregressive parameters'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-stationary starting autoregressive parameters'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-invertible starting MA parameters found.'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\base\\model.py:607: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
      "  warnings.warn(\"Maximum Likelihood optimization failed to \"\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-stationary starting autoregressive parameters'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-invertible starting MA parameters found.'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-stationary starting autoregressive parameters'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-invertible starting MA parameters found.'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\base\\model.py:607: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
      "  warnings.warn(\"Maximum Likelihood optimization failed to \"\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-stationary starting autoregressive parameters'\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "最佳ARIMA参数: (1, 1, 1), AIC: 168.81218819525648\n",
      "北京市未来3年GDP预测:\n",
      "2025年: 26049.3亿元\n",
      "2026年: 26062.2亿元\n",
      "2027年: 26073.2亿元\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-stationary starting autoregressive parameters'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-invertible starting MA parameters found.'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\base\\model.py:607: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
      "  warnings.warn(\"Maximum Likelihood optimization failed to \"\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-stationary starting autoregressive parameters'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-invertible starting MA parameters found.'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: No frequency information was provided, so inferred frequency -1YS-JAN will be used.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:473: ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.\n",
      "  self._init_dates(dates, freq)\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-stationary starting autoregressive parameters'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\statespace\\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.\n",
      "  warn('Non-invertible starting MA parameters found.'\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\base\\model.py:607: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals\n",
      "  warnings.warn(\"Maximum Likelihood optimization failed to \"\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:837: ValueWarning: No supported index is available. Prediction results will be given with an integer index beginning at `start`.\n",
      "  return get_prediction_index(\n",
      "D:\\anaconda3\\envs\\pytorch_study\\Lib\\site-packages\\statsmodels\\tsa\\base\\tsa_model.py:837: FutureWarning: No supported index is available. In the next version, calling this method in a model without a supported index will result in an exception.\n",
      "  return get_prediction_index(\n"
     ]
    }
   ],
   "execution_count": 18
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "36be5ff0c20e3d36"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "ca4f02c9e9a8145c"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "9146f1ec4d9baff6"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "38049aec7c4f858b"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "b6348e2bd76a78de"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "65e82d7ee47f4bd"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
